package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/param")
public class ParamerController {
    @RequestMapping("/commonParam")
    @ResponseBody
    public String commonParam(String name , int age){
        System.out.println("普通参数传递 name ==> "+ name);
        System.out.println("普通参数传递 age ==> "+ age);
        return "{'module':'common param'}";
    }
    @RequestMapping("commonParaByName")
    @ResponseBody
    public String commonParaByName(
            @RequestParam(value = "name1",required = false,defaultValue = "zhangsan")
            String name,
            @RequestParam("age1")int age
    ){
        System.out.println(name);
        System.out.println(age);
        return "{'info':'hahh'}";
    }
    @RequestMapping("pojoParam")
    @ResponseBody
    public String pojoParam(User user){
        System.out.println("pojo 参数传到 user ==> "+user);
        return "{'module':'pojo param'}";
    }
    @RequestMapping("pojoParam1")
    @ResponseBody
    public String pojoParam1(User user){
        System.out.println("pojo 参数传到 user ==> "+user);
        return "{'module':'pojo param'}";
    }
    @RequestMapping("/arrayParam")
    @ResponseBody
    public String arrayParam(String[] likes){
        System.out.println("数组参数传递 likes ==> "+ Arrays.toString(likes));
        return "{'module':'array param'}";
    }

    @RequestMapping("/listParam")
    @ResponseBody
    public String listParam(@RequestParam List<String> likes){
        System.out.println("集合参数传递 likes ==> "+ likes);
        return "{'module':'list param'}";
    }
}
